package com.dopies.bsdmall.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dopies.BeeFramework.Utils.TimeUtil;
import com.dopies.bsdmall.R;
import com.dopies.bsdmall.protocol.MESSAGE;

public class ShopNotifityAdapter extends BaseAdapter {

	private Context context;
	public ArrayList<MESSAGE> list;
	private LayoutInflater inflater;

    public class NotifyHolder
    {
        public TextView text;
        public TextView time;
    }
	
	public ShopNotifityAdapter(Context context, ArrayList<MESSAGE> list) {
		this.context = context;
		this.list = list;
//		this.list.clear();
		inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
    {
		// TODO Auto-generated method stub
		final NotifyHolder holder;
		if(convertView == null)
        {
			holder = new NotifyHolder();
			convertView = inflater.inflate(R.layout.shop_notify_item, null);
			holder.text = (TextView) convertView.findViewById(R.id.shop_notify_item_text);
            holder.time = (TextView)convertView.findViewById(R.id.shop_notify_item_time);
			
			convertView.setTag(holder);
		} else {
			holder = (NotifyHolder) convertView.getTag();
		}

        MESSAGE message = list.get(position);
        holder.time.setText(TimeUtil.timeAgo(message.time));
        holder.text.setText(message.content);
		
		return convertView;
	}

}
